//
//  LeaderYijianCell.m
//  Estate
//
//  Created by heyong on 16/9/7.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "LeaderYijianCell.h"

@implementation LeaderYijianCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    //这种情况是查看
//    self.titleField.borderStyle=UITextBorderStyleNone;
//    self.titleField.leftViewMode = UITextFieldViewModeAlways;
//    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
//    self.titleField.leftView=view;
//    self.titleField.adjustsFontSizeToFitWidth = YES;
}

- (void)setCellType:(NSString *)cellType State:(NSString *)state isIcon:(BOOL)icon{
    //新增
    if([cellType isEqualToString:@"add"]){
        self.titleField.layer.cornerRadius=6;
        self.stateImage.hidden=YES;

        if([state isEqualToString:@"1"]){
//            self.stateImage.image=[UIImage imageNamed:@"tongguo"];
            self.titleField.backgroundColor=[UIColor colorWithRed:0.90 green:0.94 blue:0.96 alpha:1.00];
        }else if([state isEqualToString:@"0"]){
            self.titleField.backgroundColor= [UIColor colorWithRed:0.99 green:0.94 blue:0.94 alpha:1.00];
        }
        //不合格 整改后 合格
    }else if ([cellType isEqualToString:@"query"]){
        self.titleField.layer.cornerRadius=6;
        if([state isEqualToString:@"1"]){
            if(icon){
                self.stateImage.image=[UIImage imageNamed:@"tongguo"];
                self.titleField.backgroundColor= [UIColor colorWithRed:0.99 green:0.94 blue:0.94 alpha:1.00];
            }else{
                self.titleField.backgroundColor=[UIColor colorWithRed:0.90 green:0.94 blue:0.96 alpha:1.00];
                self.stateImage.hidden=YES;
            }
        }else if([state isEqualToString:@"0"]){
            if(icon){
                self.stateImage.hidden=NO;
                self.iconLeftConstraint.constant=0.;
                self.stateImage.image=[UIImage imageNamed:@"butongguo"];
                self.titleField.backgroundColor= [UIColor colorWithRed:0.99 green:0.94 blue:0.94 alpha:1.00];
            }else{
                self.iconLeftConstraint.constant=-15.;
                self.titleField.backgroundColor=[UIColor colorWithRed:0.99 green:0.94 blue:0.94 alpha:1.00];
                self.stateImage.hidden=YES;
            }
        }
        //一次性合格
    }else if ([cellType isEqualToString:@"firstQualified"]){
        self.stateImage.image=[UIImage imageNamed:@"tongguo"];
        self.titleField.backgroundColor=[UIColor colorWithRed:0.90 green:0.94 blue:0.96 alpha:1.00];
        //整改完 待审阅
    }else if ([cellType isEqualToString:@"zheng"]){
        self.stateImage.image=[UIImage imageNamed:@"zhenggai_state"];
        self.titleField.backgroundColor= [UIColor colorWithRed:0.99 green:0.94 blue:0.94 alpha:1.00];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

//- (IBAction)textChange:(UITextField *)sender {
//    if(self.textValueChangedBlock){
//        self.textValueChangedBlock(sender.text);
//    }
//}

- (void)textViewDidChange:(UITextView *)textView
{
    if ([self.delegate respondsToSelector:@selector(textViewCell:didChangeText:)]) {
        [self.delegate textViewCell:self didChangeText:textView.text];
    }
    CGRect bounds = textView.bounds;
    // 计算 text view 的高度
    CGSize maxSize = CGSizeMake(bounds.size.width, CGFLOAT_MAX);
    CGSize newSize = [textView sizeThatFits:maxSize];
    bounds.size = newSize;
    textView.bounds = bounds;
    // 让 table view 重新计算高度
    UITableView *tableView = [self tableView];
    [tableView beginUpdates];
    [tableView endUpdates];
}

- (UITableView *)tableView
{
    UIView *tableView = self.superview;
    while (![tableView isKindOfClass:[UITableView class]] && tableView) {
        tableView = tableView.superview;
    }
    return (UITableView *)tableView;
}

- (IBAction)clickDltBtn:(UIButton *)sender {
    if(self.dltBlock){
        self.dltBlock();
    }
}

- (IBAction)clickDeilte:(UIButton *)sender {
    if(self.detailBlick){
        self.detailBlick();
    }
}
- (void)setIsEdit:(BOOL)isEdit{
    self.titleField.userInteractionEnabled=isEdit;
    if(!isEdit){
        self.deleteBtn.hidden=YES;
        self.leftConstraint.constant=-25.*BIZ;
    }
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"detailss";
    LeaderYijianCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[LeaderYijianCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.name.textColor=UIColorFromRGB(0x787878);
    cell.name.font=[UIFont systemFontOfSize:16*BIZ];
    cell.titleField.textColor=UIColorFromRGB(0x787878);
    cell.titleField.font=[UIFont systemFontOfSize:16*BIZ];
    return cell;
}

@end


